<!-- // 获取当前属性 -->
<template>
    <div>
        <el-card>
            <template #header>
                <span class="title-span">API基础信息</span>
            </template>
            <!-- // 两个输入框  一个是名称  一个是描述 -->
            <el-form label-width="100">
                <el-form-item label="节点名称：">
                    <el-input v-model="props.showFlowData.data.label"></el-input>
                </el-form-item>
                <el-form-item label="描述：">
                    <el-input v-model="props.showFlowData.data.desc" type="textarea"></el-input>
                </el-form-item>
            </el-form>
        </el-card>

    </div>
</template>

<script setup>
import { ref, defineProps, onMounted, watch } from 'vue';
import flowNodesStore from '@/store/modules/flowNodes'
const { proxy } = getCurrentInstance();
const flowNodes = flowNodesStore()
const props = defineProps({
    // Define props here
    showFlowData: {
        type: Object,
    },
    drawer: {
        type: Boolean,
    },
    recapture: {
        type: Boolean
    },
    inputSelectNodeIds: {
        type: Array
    }
});


const popShowData = ref({
    APIBaseData: {
        name: '结束节点',
        desc: '结束节点',
    },
})

const node_data = computed(() => {
    let obj = {
        positionFlag: props.showFlowData.data.positionFlag, // 是否开始结束节点
        methodName: props.showFlowData.data.methodName,
        input3DData: props.showFlowData.id,
    }
    return obj;
});

// watch(() => props.drawer, (val) => {
//   if (!val) {
//     setData();// 更新数据
//   }
// }, { deep: true }, { immediate: true })

watch(() => popShowData.value, (val) => {
    if (val) {
        setData();// 更新数据
    }
}, { deep: true }, { immediate: true })


watch(() => props.recapture, (val) => {
    reset();
    getList();
}, { deep: true }, { immediate: true })


onMounted(() => {
    getList();
    setData();
})

const getList = () => {
    if (props.showFlowData.id) {
        if (flowNodes.getFlowNodesById(props.showFlowData.id)) {
            let nodeData = flowNodes.getFlowNodesById(props.showFlowData.id);
            if (nodeData.data.popShowData) {
                popShowData.value = JSON.parse(JSON.stringify(nodeData.data.popShowData))
            } else {
                reset();
            }
        }
    }
}

const setData = () => {
    let nodeData = flowNodes.getFlowNodesById(props.showFlowData.id);
    // 如果找到了该节点，则更新数据
    if (nodeData) {
        // nodeData.data.popShowData = popShowData.value
        nodeData.data.popShowData = JSON.parse(JSON.stringify(popShowData.value))
        nodeData.data.data = node_data.value
        flowNodes.setFlowNodesById(props.showFlowData.id, nodeData)
    }
}

const reset = () => {
    popShowData.value = {
        APIBaseData: {
            name: '获取当前数据',
            desc: '获取当前窗口打开的3D数据',
        },
    }
}
</script>

<style scoped>
/* Your component styles go here */
</style>